package cn.iocoder.yudao.module.vehicle.controller.admin.vehicleinfo;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.vehicle.controller.admin.vehicleinfo.vo.*;
import cn.iocoder.yudao.module.vehicle.dal.dataobject.vehicleinfo.vehicleinfoDO;
import cn.iocoder.yudao.module.vehicle.service.vehicleinfo.vehicleinfoService;

@Tag(name = "管理后台 - 车辆基本信息")
@RestController
@RequestMapping("/vehicle/vehicleinfo")
@Validated
public class vehicleinfoController {

    @Resource
    private vehicleinfoService vehicleinfoService;

    @PostMapping("/create")
    @Operation(summary = "创建车辆基本信息")
    @PreAuthorize("@ss.hasPermission('vehicle:vehicleinfo:create')")
    public CommonResult<Long> createvehicleinfo(@Valid @RequestBody vehicleinfoSaveReqVO createReqVO) {
        return success(vehicleinfoService.createvehicleinfo(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新车辆基本信息")
    @PreAuthorize("@ss.hasPermission('vehicle:vehicleinfo:update')")
    public CommonResult<Boolean> updatevehicleinfo(@Valid @RequestBody vehicleinfoSaveReqVO updateReqVO) {
        vehicleinfoService.updatevehicleinfo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除车辆基本信息")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('vehicle:vehicleinfo:delete')")
    public CommonResult<Boolean> deletevehicleinfo(@RequestParam("id") Long id) {
        vehicleinfoService.deletevehicleinfo(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除车辆基本信息")
                @PreAuthorize("@ss.hasPermission('vehicle:vehicleinfo:delete')")
    public CommonResult<Boolean> deletevehicleinfoList(@RequestParam("ids") List<Long> ids) {
        vehicleinfoService.deletevehicleinfoListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得车辆基本信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('vehicle:vehicleinfo:query')")
    public CommonResult<vehicleinfoRespVO> getvehicleinfo(@RequestParam("id") Long id) {
        vehicleinfoDO vehicleinfo = vehicleinfoService.getvehicleinfo(id);
        return success(BeanUtils.toBean(vehicleinfo, vehicleinfoRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得车辆基本信息分页")
    @PreAuthorize("@ss.hasPermission('vehicle:vehicleinfo:query')")
    public CommonResult<PageResult<vehicleinfoRespVO>> getvehicleinfoPage(@Valid vehicleinfoPageReqVO pageReqVO) {
        PageResult<vehicleinfoDO> pageResult = vehicleinfoService.getvehicleinfoPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, vehicleinfoRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出车辆基本信息 Excel")
    @PreAuthorize("@ss.hasPermission('vehicle:vehicleinfo:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportvehicleinfoExcel(@Valid vehicleinfoPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<vehicleinfoDO> list = vehicleinfoService.getvehicleinfoPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "车辆基本信息.xls", "数据", vehicleinfoRespVO.class,
                        BeanUtils.toBean(list, vehicleinfoRespVO.class));
    }

}